<?php

/**
 * Lumad CMS
 * Copyright (c)	2007, Jason A. Banico
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright (c) 2007, Jason A. Banico
 * @link			http://cakeforge.org/projects/lumad-cms/
 * @package			lumad-cms
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/*
 *  This component is used for checking the context of the current controller, for use by
 *  admin elements such as menus and submenus. It also checks sessions whether the user is logged on.
*/

class ContextComponent extends Object {

  var $method = '';
  var $session = '';
  var $name = '';

  // assigns values of referencing controller
  function startup(&$controller) {
    $this->session=$controller->Session->check('User');
    $this->name=$controller->name;
  }

  function checkSession(&$controller) {
    if (!$this->session) {
      $controller->redirect('/admin/users/login');
      exit();
    }
  }

  function currentcontroller($id) {
    if ($id==$this->name) {
      return 'current';
    }
  }

  function currentmethod($id) {
    if ($id==$this->method) {
      return 'current';
    }
  }

}
?>